/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Administrator
 */
public class yianzhuangcw extends HttpServlet {

    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        int i = Integer.parseInt(request.getParameter("i"));

        String data1 = "{\"count\":2,\"list\":[{\"huiruzhanghao\":\"15000000023\",\"kehuming\":\"朱颖\",\"ysjine\":132,\"jixing\":\"淋浴花洒套装\",\"hkriqi\":\"\",\"anzhuangdizhi\":\"红叶山庄6号楼1单元1203室\",\"kehuID\":\"13855239889\",\"fukuanzhuangtai\":\"\"},{\"huiruzhanghao\":\"15000000023\",\"kehuming\":\"朱颖\",\"ysjine\":100,\"jixing\":\"淋浴花洒套装\",\"hkriqi\":\"\",\"anzhuangdizhi\":\"红叶山庄6号楼1单元1203室\",\"kehuID\":\"13855239889\",\"fukuanzhuangtai\":\"\"}]}";
        String data2 = "{\"count\":3,\"list\":[{\"huiruzhanghao\":\"15000000001\",\"kehuming\":\"李传顺\",\"ysjine\":340,\"jixing\":\"淋浴花洒套装\",\"hkriqi\":\"2013-12-05\",\"anzhuangdizhi\":\"西河南路桥头\",\"kehuID\":\"18133229861\",\"fukuanzhuangtai\":\"\"},{\"huiruzhanghao\":\"15000000001\",\"kehuming\":\"简俊岭\",\"ysjine\":200,\"jixing\":\"即热型电热水器\",\"hkriqi\":\"2014-01-03\",\"anzhuangdizhi\":\"华地学府名都19栋706室\",\"kehuID\":\"15215698682\",\"fukuanzhuangtai\":\"\"},{\"huiruzhanghao\":\"15000000001\",\"kehuming\":\"xql\",\"ysjine\":80,\"jixing\":\"储水型电热水器\",\"hkriqi\":\"2014-04-25\",\"anzhuangdizhi\":\"东方银座7#501\",\"kehuID\":\"15060897323\",\"fukuanzhuangtai\":\"\"}]}";
        String data = "";
        if (i > 5) {

            data = "{\"count\":0,\"list\":[]}";
        } else if (i % 2 != 0) {
            System.out.println(i % 2);
            data = data1;
        } else {
            System.out.println(i % 2);
            data = data2;
        }

        response.setContentType("text/html;charset=gb2312");
        response.setHeader("Access-Control-Allow-Origin", "*");
        try (PrintWriter out = response.getWriter()) {
            out.println(data);
            out.flush();
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
